#region License
/* Copyright (C) 2009 Tim Coulter
 * 
 * This file is part of ExtremeML.
 * 
 * ExtremeML is free software: you can redistribute
 * it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
 * the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
*/
#endregion

using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using ExtremeML.Core;
using ExtremeML.Packaging;
using ExtremeML.Spreadsheet;

namespace ExtremeML.Packaging
{
	/// <summary>
	/// Maintains a collection of <see cref="ExtremeML.Packaging.ImagePartWrapper"/>.
	/// </summary>
	/// <seealso cref="ExtremeML.Packaging.ImagePartWrapper"/>
	[GeneratedCode("T4", "1.0")]
	public sealed partial class ImagePartWrapperCollection : PartWrapperCollection<ExtremeML.Packaging.ImagePartWrapper, DocumentFormat.OpenXml.Packaging.ImagePart>
	{

		/// <summary>
		/// Initializes a new instance of the <see cref="ImagePartWrapperCollection"/> class.
		/// </summary>
		/// <param name="wrapped">An <see cref="OpenXmlPartContainer"/> from which to populate this instance.</param>
		/// <param name="parent">An <see cref="IContentWrapper"/> that represents the parent wrapper instance.</param>
		/// <param name="package">An <see cref="IContentWrapper"/> that represents the package wrapper instance.</param>
		internal ImagePartWrapperCollection(
			OpenXmlPartContainer wrapped,
			IContentWrapper parent,
			IContentWrapper package)
			: base(wrapped, parent, package)
		{
		}
		

		/// <summary>
		/// Extracts collection members from the wrapped content object.
		/// </summary>
		protected override void OnDecomposing()
		{
			base.OnDecomposing();
			Items.AddRange(from item in Wrapped.GetPartsOfType<DocumentFormat.OpenXml.Packaging.ImagePart>() select new ExtremeML.Packaging.ImagePartWrapper(item, this, Package));
		}

		/// <summary>
		/// Re-creates the wrapped content object from collection members.
		/// </summary>
		/// <param name="parent">An <see cref="OpenXmlPartContainer"/> that represents the parent content object.</param>
		internal void Recompose(
			OpenXmlPartContainer parent)
		{
			OnCustomRecomposing();
			if (Recomposing != null) Recomposing();

			foreach (var item in Items)
			{
				item.Recompose(parent);
			}

			OnCustomRecomposed();
			if (Recomposed != null) Recomposed();
		}

		/// <summary>
		/// Occurs when a this instance is requested to persist its content.
		/// </summary>
		private event VoidEventHandler Recomposing;

		/// <summary>
		/// Occurs after a this instance has persisted its content.
		/// </summary>
		private event VoidEventHandler Recomposed;

		/// <summary>
		/// Creates a new member wrapper instance populated with default content.
		/// </summary>
	    /// <param name="args">A parameter array of <see cref="object"/> containing member initialization arguments.</param>
		/// <returns>A new <see cref="ExtremeML.Packaging.ImagePartWrapper"/> instance.</returns>
		protected override ExtremeML.Packaging.ImagePartWrapper CreateDefaultMemberWrapper(
			params object[] args)
		{
			return new ExtremeML.Packaging.ImagePartWrapper(ExtremeML.Packaging.ImagePartWrapper.CreateDefaultPart(Wrapped, args), this, Package);
		}
	}
}

namespace ExtremeML.Packaging
{
	/// <summary>
	/// Maintains a collection of <see cref="ExtremeML.Packaging.WorksheetPartWrapper"/>.
	/// </summary>
	/// <seealso cref="ExtremeML.Packaging.WorksheetPartWrapper"/>
	[GeneratedCode("T4", "1.0")]
	public sealed partial class WorksheetPartWrapperCollection : PartWrapperCollection<ExtremeML.Packaging.WorksheetPartWrapper, DocumentFormat.OpenXml.Packaging.WorksheetPart>
	{

		/// <summary>
		/// Initializes a new instance of the <see cref="WorksheetPartWrapperCollection"/> class.
		/// </summary>
		/// <param name="wrapped">An <see cref="OpenXmlPartContainer"/> from which to populate this instance.</param>
		/// <param name="parent">An <see cref="IContentWrapper"/> that represents the parent wrapper instance.</param>
		/// <param name="package">An <see cref="IContentWrapper"/> that represents the package wrapper instance.</param>
		internal WorksheetPartWrapperCollection(
			OpenXmlPartContainer wrapped,
			IContentWrapper parent,
			IContentWrapper package)
			: base(wrapped, parent, package)
		{
		}
		

		/// <summary>
		/// Extracts collection members from the wrapped content object.
		/// </summary>
		protected override void OnDecomposing()
		{
			base.OnDecomposing();
			Items.AddRange(from item in Wrapped.GetPartsOfType<DocumentFormat.OpenXml.Packaging.WorksheetPart>() select new ExtremeML.Packaging.WorksheetPartWrapper(item, this, Package));
		}

		/// <summary>
		/// Re-creates the wrapped content object from collection members.
		/// </summary>
		/// <param name="parent">An <see cref="OpenXmlPartContainer"/> that represents the parent content object.</param>
		internal void Recompose(
			OpenXmlPartContainer parent)
		{
			OnCustomRecomposing();
			if (Recomposing != null) Recomposing();

			foreach (var item in Items)
			{
				item.Recompose(parent);
			}

			OnCustomRecomposed();
			if (Recomposed != null) Recomposed();
		}

		/// <summary>
		/// Occurs when a this instance is requested to persist its content.
		/// </summary>
		private event VoidEventHandler Recomposing;

		/// <summary>
		/// Occurs after a this instance has persisted its content.
		/// </summary>
		private event VoidEventHandler Recomposed;

		/// <summary>
		/// Creates a new member wrapper instance populated with default content.
		/// </summary>
	    /// <param name="args">A parameter array of <see cref="object"/> containing member initialization arguments.</param>
		/// <returns>A new <see cref="ExtremeML.Packaging.WorksheetPartWrapper"/> instance.</returns>
		protected override ExtremeML.Packaging.WorksheetPartWrapper CreateDefaultMemberWrapper(
			params object[] args)
		{
			return new ExtremeML.Packaging.WorksheetPartWrapper(ExtremeML.Packaging.WorksheetPartWrapper.CreateDefaultPart(Wrapped, args), this, Package);
		}
	}
}

namespace ExtremeML.Packaging
{
	/// <summary>
	/// Maintains a collection of <see cref="ExtremeML.Packaging.VmlDrawingPartWrapper"/>.
	/// </summary>
	/// <seealso cref="ExtremeML.Packaging.VmlDrawingPartWrapper"/>
	[GeneratedCode("T4", "1.0")]
	public sealed partial class VmlDrawingPartWrapperCollection : PartWrapperCollection<ExtremeML.Packaging.VmlDrawingPartWrapper, DocumentFormat.OpenXml.Packaging.VmlDrawingPart>
	{

		/// <summary>
		/// Initializes a new instance of the <see cref="VmlDrawingPartWrapperCollection"/> class.
		/// </summary>
		/// <param name="wrapped">An <see cref="OpenXmlPartContainer"/> from which to populate this instance.</param>
		/// <param name="parent">An <see cref="IContentWrapper"/> that represents the parent wrapper instance.</param>
		/// <param name="package">An <see cref="IContentWrapper"/> that represents the package wrapper instance.</param>
		internal VmlDrawingPartWrapperCollection(
			OpenXmlPartContainer wrapped,
			IContentWrapper parent,
			IContentWrapper package)
			: base(wrapped, parent, package)
		{
		}
		

		/// <summary>
		/// Extracts collection members from the wrapped content object.
		/// </summary>
		protected override void OnDecomposing()
		{
			base.OnDecomposing();
			Items.AddRange(from item in Wrapped.GetPartsOfType<DocumentFormat.OpenXml.Packaging.VmlDrawingPart>() select new ExtremeML.Packaging.VmlDrawingPartWrapper(item, this, Package));
		}

		/// <summary>
		/// Re-creates the wrapped content object from collection members.
		/// </summary>
		/// <param name="parent">An <see cref="OpenXmlPartContainer"/> that represents the parent content object.</param>
		internal void Recompose(
			OpenXmlPartContainer parent)
		{
			OnCustomRecomposing();
			if (Recomposing != null) Recomposing();

			foreach (var item in Items)
			{
				item.Recompose(parent);
			}

			OnCustomRecomposed();
			if (Recomposed != null) Recomposed();
		}

		/// <summary>
		/// Occurs when a this instance is requested to persist its content.
		/// </summary>
		private event VoidEventHandler Recomposing;

		/// <summary>
		/// Occurs after a this instance has persisted its content.
		/// </summary>
		private event VoidEventHandler Recomposed;

		/// <summary>
		/// Creates a new member wrapper instance populated with default content.
		/// </summary>
	    /// <param name="args">A parameter array of <see cref="object"/> containing member initialization arguments.</param>
		/// <returns>A new <see cref="ExtremeML.Packaging.VmlDrawingPartWrapper"/> instance.</returns>
		protected override ExtremeML.Packaging.VmlDrawingPartWrapper CreateDefaultMemberWrapper(
			params object[] args)
		{
			return new ExtremeML.Packaging.VmlDrawingPartWrapper(ExtremeML.Packaging.VmlDrawingPartWrapper.CreateDefaultPart(Wrapped, args), this, Package);
		}
	}
}

namespace ExtremeML.Packaging
{
	/// <summary>
	/// Maintains a collection of <see cref="ExtremeML.Packaging.TableDefinitionPartWrapper"/>.
	/// </summary>
	/// <seealso cref="ExtremeML.Packaging.TableDefinitionPartWrapper"/>
	[GeneratedCode("T4", "1.0")]
	public sealed partial class TableDefinitionPartWrapperCollection : PartWrapperCollection<ExtremeML.Packaging.TableDefinitionPartWrapper, DocumentFormat.OpenXml.Packaging.TableDefinitionPart>
	{

		/// <summary>
		/// Initializes a new instance of the <see cref="TableDefinitionPartWrapperCollection"/> class.
		/// </summary>
		/// <param name="wrapped">An <see cref="OpenXmlPartContainer"/> from which to populate this instance.</param>
		/// <param name="parent">An <see cref="IContentWrapper"/> that represents the parent wrapper instance.</param>
		/// <param name="package">An <see cref="IContentWrapper"/> that represents the package wrapper instance.</param>
		internal TableDefinitionPartWrapperCollection(
			OpenXmlPartContainer wrapped,
			IContentWrapper parent,
			IContentWrapper package)
			: base(wrapped, parent, package)
		{
		}
		

		/// <summary>
		/// Extracts collection members from the wrapped content object.
		/// </summary>
		protected override void OnDecomposing()
		{
			base.OnDecomposing();
			Items.AddRange(from item in Wrapped.GetPartsOfType<DocumentFormat.OpenXml.Packaging.TableDefinitionPart>() select new ExtremeML.Packaging.TableDefinitionPartWrapper(item, this, Package));
		}

		/// <summary>
		/// Re-creates the wrapped content object from collection members.
		/// </summary>
		/// <param name="parent">An <see cref="OpenXmlPartContainer"/> that represents the parent content object.</param>
		internal void Recompose(
			OpenXmlPartContainer parent)
		{
			OnCustomRecomposing();
			if (Recomposing != null) Recomposing();

			foreach (var item in Items)
			{
				item.Recompose(parent);
			}

			OnCustomRecomposed();
			if (Recomposed != null) Recomposed();
		}

		/// <summary>
		/// Occurs when a this instance is requested to persist its content.
		/// </summary>
		private event VoidEventHandler Recomposing;

		/// <summary>
		/// Occurs after a this instance has persisted its content.
		/// </summary>
		private event VoidEventHandler Recomposed;

		/// <summary>
		/// Creates a new member wrapper instance populated with default content.
		/// </summary>
	    /// <param name="args">A parameter array of <see cref="object"/> containing member initialization arguments.</param>
		/// <returns>A new <see cref="ExtremeML.Packaging.TableDefinitionPartWrapper"/> instance.</returns>
		protected override ExtremeML.Packaging.TableDefinitionPartWrapper CreateDefaultMemberWrapper(
			params object[] args)
		{
			return new ExtremeML.Packaging.TableDefinitionPartWrapper(ExtremeML.Packaging.TableDefinitionPartWrapper.CreateDefaultPart(Wrapped, args), this, Package);
		}
	}
}

namespace ExtremeML.Packaging
{
	/// <summary>
	/// Maintains a collection of <see cref="ExtremeML.Packaging.QueryTablePartWrapper"/>.
	/// </summary>
	/// <seealso cref="ExtremeML.Packaging.QueryTablePartWrapper"/>
	[GeneratedCode("T4", "1.0")]
	public sealed partial class QueryTablePartWrapperCollection : PartWrapperCollection<ExtremeML.Packaging.QueryTablePartWrapper, DocumentFormat.OpenXml.Packaging.QueryTablePart>
	{

		/// <summary>
		/// Initializes a new instance of the <see cref="QueryTablePartWrapperCollection"/> class.
		/// </summary>
		/// <param name="wrapped">An <see cref="OpenXmlPartContainer"/> from which to populate this instance.</param>
		/// <param name="parent">An <see cref="IContentWrapper"/> that represents the parent wrapper instance.</param>
		/// <param name="package">An <see cref="IContentWrapper"/> that represents the package wrapper instance.</param>
		internal QueryTablePartWrapperCollection(
			OpenXmlPartContainer wrapped,
			IContentWrapper parent,
			IContentWrapper package)
			: base(wrapped, parent, package)
		{
		}
		

		/// <summary>
		/// Extracts collection members from the wrapped content object.
		/// </summary>
		protected override void OnDecomposing()
		{
			base.OnDecomposing();
			Items.AddRange(from item in Wrapped.GetPartsOfType<DocumentFormat.OpenXml.Packaging.QueryTablePart>() select new ExtremeML.Packaging.QueryTablePartWrapper(item, this, Package));
		}

		/// <summary>
		/// Re-creates the wrapped content object from collection members.
		/// </summary>
		/// <param name="parent">An <see cref="OpenXmlPartContainer"/> that represents the parent content object.</param>
		internal void Recompose(
			OpenXmlPartContainer parent)
		{
			OnCustomRecomposing();
			if (Recomposing != null) Recomposing();

			foreach (var item in Items)
			{
				item.Recompose(parent);
			}

			OnCustomRecomposed();
			if (Recomposed != null) Recomposed();
		}

		/// <summary>
		/// Occurs when a this instance is requested to persist its content.
		/// </summary>
		private event VoidEventHandler Recomposing;

		/// <summary>
		/// Occurs after a this instance has persisted its content.
		/// </summary>
		private event VoidEventHandler Recomposed;

		/// <summary>
		/// Creates a new member wrapper instance populated with default content.
		/// </summary>
	    /// <param name="args">A parameter array of <see cref="object"/> containing member initialization arguments.</param>
		/// <returns>A new <see cref="ExtremeML.Packaging.QueryTablePartWrapper"/> instance.</returns>
		protected override ExtremeML.Packaging.QueryTablePartWrapper CreateDefaultMemberWrapper(
			params object[] args)
		{
			return new ExtremeML.Packaging.QueryTablePartWrapper(ExtremeML.Packaging.QueryTablePartWrapper.CreateDefaultPart(Wrapped, args), this, Package);
		}
	}
}

